let $axios = require('axios')
$axios.defaults.baseURL = 'http://localhost:8090/api'

/**
 * 导出商品列表Excel接口
 * @param param
 * @returns {Promise<unknown>}
 */
export function exportExcelAll(param) {
  return new Promise((resolve, reject) => {
    $axios.post('/goods/exportExcelAll',param,{
      procgress:true,
      responseType:'blob',
    }).then(resp=>{
      if(resp&&resp.status==200){
        resolve(resp.data)
      }
      reject(resp);
    })
  })
}

/**
 * 加载全部商品列表接口
 * @returns {Promise<unknown>}
 */
export function loadAllGoods(){
  return new Promise((resolve, reject) => {
    $axios.get('/goods').then(resp=>{
      if(resp&&resp.status==200){
        resolve(resp.data);
      }
      reject(resp);
    })
  })
}

/**
 * 商品模糊查询接口
 * @param query
 * @returns {null|Promise<unknown>}
 */
export function selectGoods(query){
  console.log('请求URL=/api/goods/goods/'+query);
  return query==''? null : new Promise((resolve, reject) => {
    $axios.get('/goods/goods/'+query).then(resp=>{
      if(resp && resp.status==200){
        resolve(resp);
      }
      reject(resp);
    })
  });
}

export function addGood(good){
  return new Promise((resolve, reject) => {
    $axios.post('/goods/add', good).then(resp=>{
      if(resp&&resp.status==200){
        resolve(resp);
      }
      reject(resp);
    })
  })
}
